package model.scriptrunner;

import static org.junit.Assert.*

import java.util.AbstractList;

import model.humanbody.BodyBuilder
import model.humanbody.HumanBody

import org.junit.After
import org.junit.AfterClass
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test



class ScriptRunnerTest {
	def questioner = new Questioner()
	
	//构造一个HumanBody
	HumanBody body = BodyBuilder.build("data/data_test.xls", "主体_测试", "外部影响_测试")

	//构造ScriptRunner，把body和脚本文件夹路径传给它
	ScriptRunner sr = new ScriptRunner(body,"relations",questioner)
	
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	class Questioner implements QuestionableInterface{
		static count = 0
		@Override
		public AbstractList ask(String questions) {
			count ++
			return ["低热（37．4～38℃）","舌边尖红", "口微渴", "咽部肿痛"];
			
		}
		@Override
		public Boolean askYesNo(String question) {
			// TODO 弹个yesno框出来
			return null;
		}

	}
	
	@Test
	public void testRun() {

		//println sr.script

		// 简单测试
		sr.script = "风温之邪_伊波拉 ++"

		sr.run()

		assert( body.风温之邪_伊波拉 == 1.0)

		// 脚本测试
		sr.reload()
		sr.resetTicks()
		body.reset()

		assert( body.风温之邪_伊波拉 == 0)

		//println sr.script

		body.setCondition("风温之邪_伊波拉",1)

		assert(body.风温之邪_伊波拉 == 1)
		
		sr.run()
		assert( sr.ticks == 1)
		
		assert(body.风热袭表 == 1)
		assert(body.气分热盛 == 0)
		
		sr.run()
		assert( sr.ticks == 2)
		
		assert(body.风热袭表 == 1)
		assert(body.气分热盛 == 1)
		assert(body.营分热盛 == 0)
		
		sr.run()
		assert( sr.ticks == 3)
		
		assert(body.风热袭表 == 1)
		assert(body.气分热盛 == 1)
		assert(body.营分热盛 == 1)
		
//		assert(body.风热袭表 == 0)
//
//		assert(body.气分热盛 == 0)
//		assert(body.营分热盛 == 0)
//		assert(body.血分热盛 == 0)
//
//		//println body.气分热盛
//
//		sr.run()
//
//		assert(questioner.count == 1)
//		
//		assert(body.风温之邪_伊波拉 == 1)
//		//println body.风热袭表
//		assert(body.风热袭表 == 0)
//
//		assert(body.气分热盛 == 0)
//		assert(body.营分热盛 == 0)
//		assert(body.血分热盛 == 0)
//		
//		//println body.getStatus()
//		sr.run()
//		
//		sr.run()
//		
//		sr.run()
//		
//		//println questioner.count
//		assert(questioner.count == 1)

	}
	
	@Test
	public void testQuestions(){
		//def script = "askSingle(\"头痛部位\",\"请问你头痛的部位是？\",[\"A\",\"B\",\"C\"])"
		//sr.run(script)
	}
}

